package com.wanshi.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@WebFilter(filterName = "LuanMaFilter",urlPatterns = "/*")
public class LuanMaFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest request, ServletResponse resp, FilterChain chain) throws ServletException, IOException {

        resp.setContentType("text/html;charset=utf-8");

        //判断 提交方式 必须是post 才需要解决
        HttpServletRequest req = (HttpServletRequest) request;
        String method = req.getMethod();

        if("post".equalsIgnoreCase(method)){
            req.setCharacterEncoding("utf-8");
        }

        chain.doFilter(req, resp);
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
